package com.china08.yxyapi.util;

import java.io.File;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;

import it.sauronsoftware.jave.Encoder;
import it.sauronsoftware.jave.MultimediaInfo;

@Component
public class YXGetVideoInfoUtil {

    private static final Logger LOGGER = LoggerFactory.getLogger(YXGetVideoInfoUtil.class);

    /**
     * 获取时长
     * 
     */
    public long getDuration(String path) throws Exception {
        File source = new File(path);
        if (source.exists()) {
            Encoder encoder = new Encoder();
            MultimediaInfo multimediaInfo = encoder.getInfo(source);
            long ls = multimediaInfo.getDuration();
            LOGGER.info("此视频时长为:::::::::::" + ls);
            return ls;
        }
        return 0l;
    }
}
